﻿
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE 2 | Log in</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link href="~/Content/css/bootstrap.css" rel="stylesheet" />
    <link href="~/Content/css/font-awesome.min.css" rel="stylesheet" />
    <link href="~/Content/css/ionicons.css" rel="stylesheet" />
    <link href="~/Content/css/AdminLTE.min.css" rel="stylesheet" />
    <link href="~/Content/css/icheck/blue.css" rel="stylesheet" />
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition login-page">
    <div class="login-box">
        <div class="login-logo">
            <a href="/Home/Index"><b>EY</b>Web</a>
        </div>
        <!-- /.login-logo -->
        <div class="login-box-body">
            <p class="login-box-msg">Sign in to start your session</p>
            <form>
                <div class="form-group has-feedback">
                    <input type="text" class="form-control" placeholder="用户名" id="txtAccount" value="wei">
                    <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback">
                    <input type="password" class="form-control" placeholder="密码" id="txtPass" value="weiabc">
                    <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback">
                    <input type="text" id="txtCode" maxlength="4" class="form-control" placeholder="验证码" style="width: 100px;float:left" value="5678" />
                    <img id="imgCode" class="authcode" src="~/Login/GetAuthCode" style="margin-left:10px" />
                </div>
                <div style="clear:both"></div>
                <div class="row">
                    <div class="col-xs-8">
                        <div class="checkbox icheck">
                            <label>
                                <input type="checkbox"> 记住
                            </label>
                        </div>
                    </div>
                    <!-- /.col -->
                    <div class="col-xs-4">
                        <button type="button" class="btn btn-primary btn-block btn-flat" id="btnLogin"><span>登 录</span></button>
                    </div>
                    <!-- /.col -->

                </div>
            </form>

            <div class="login_tips" style="color:red;"></div>
        </div>
        <!-- /.login-box-body -->
    </div>
    <!-- /.login-box -->
    <script src="~/Content/js/plugins/jquery/jquery-2.2.4.js"></script>
    <script src="~/Content/js/plugins/bootstrap/bootstrap.js"></script>
    <script src="~/Content/js/plugins/icheck/icheck.js"></script>
    <script src="~/Content/js/plugins/cookie/jquery.cookie.js"></script>
    <script src="~/Content/js/md5/jquery.md5.js"></script>
    <script>
        $(function () {
            $('input').iCheck({
                checkboxClass: 'icheckbox_minimal-blue',
                radioClass: 'iradio_minimal-blue',
                increaseArea: '20%' /* optional */
            });

            $("#txtAccount").focus();
            var error = top.$.cookie("login_error");
            if (error != null) {
                switch (error) {
                    case 'Overdue':
                        fromMessage("登录已超时,请重新登录.")
                        break;
                    case 'OnLine':
                        fromMessage("你的账号已在其他地方登录.");
                        break;
                    case '-1':
                        fromMessage("未知错误,请重新登录.");
                        break;
                }
                top.$.cookie("login_error", "", { path: "/", expires: -1 });
            }
            document.onkeydown = function (e) {
                if (!e) e = window.event;
                if ((e.keyCode || e.which) == 13) {
                    $("#btnLogin").trigger("click");
                }
            }
            //点击图片更换验证码
            $("#imgCode").click(function () {
                $(this).attr("src", "/Login/GetAuthCode?time=" + Math.random());
            });
            $("#btnLogin").click(function () {
                login();
            });
            function login() {
                var $user = $("#txtAccount");
                var $pass = $("#txtPass");
                var $code = $("#txtCode");
                if ($user.val() == "") {
                    fromMessage("请输入用户名.");
                    $user.focus();
                    return false;
                }
                if ($pass.val() == "") {
                    fromMessage("请输入密码.");
                    $pass.focus();
                    return false;
                }
                if ($code.val() == "") {
                    fromMessage("请输入验证码.");
                    $code.focus();
                    return false;
                }

                $("#btnLogin").attr("disabled", "disabled").find("span").html("Loading...");
                $.ajax({
                    url: "/Login/CheckLogin",
                    data: {
                        user: $.trim($user.val()),
                        pass: $.md5($.trim($pass.val())),
                        code: $.trim($code.val())
                    },
                    type: "post",
                    dataType: "json",
                    success: function (data) {
                        if (data.state == "success") {
                            $("#btnLogin").find("span").html("登录成功.");
                            window.setTimeout(function () {
                                window.location.href = "/Home/Index"
                            }, 1000);
                        }
                        else {
                            $("#btnLogin").removeAttr("disabled").find("span").html("登录");
                            fromMessage(data.message);
                            $code.val("");
                            $code.trigger("click");
                        }
                    }

                });

            }

            //显示错误信息
            function fromMessage(msg) {
                $(".login_tips").find(".tips_msg").remove();
                $(".login_tips").append("<div class='tips_msg'><i class='fa fa-question-circle'></i>" + msg + "</div>");
            }
        });
    </script>
</body>
</html>


